package router

import (
	"yundata-service/ws"

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func InitApiRouter(e *gin.Engine) {

	// Set up CORS options
	config := cors.DefaultConfig()
	config.AllowOrigins = []string{"*"}
	config.AllowMethods = []string{"*"}
	config.AllowHeaders = []string{"*"}
	config.ExposeHeaders = []string{"Content-Type:application/json", "If-Match", "If-Modified-Since", "If-None-Match", "If-Unmodified-Since", "X-Requested-With", "Authorization", "X-Token", "OPTIONS"}
	e.Use(cors.New(config))

	// websocket
	hub := ws.NewHub()
	go hub.Run()
	e.GET("/ws", func(c *gin.Context) {
		ws.ServeWs(hub, c.Writer, c.Request)
	})

	// 登录、注册、找回密码
	InitPassportRouter(e)

	// 初始化menu
	InitMenuRouter(e)

	// 初始化客资模块
	InitMemberRouter(e)

	// 初始化用户模块
	InitUserRouter(e)
}
